package com.joysuch.wwyt.bp.entity;

import com.joysuch.wwyt.core.support.AutoSetCommonFieldListener;
import lombok.Data;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

import static javax.persistence.GenerationType.IDENTITY;

@EntityListeners({AuditingEntityListener.class, AutoSetCommonFieldListener.class})
@Entity
@Table(name = "wwyt_bp_work_safety_cert_identify")
@SQLDelete(sql = "update wwyt_bp_work_safety_cert_identify set DELETE_FLAG = '1' where id= ?")
@SQLDeleteAll(sql = "update wwyt_bp_work_safety_cert_identify set DELETE_FLAG = '1' where id= ?")
@Where(clause = "DELETE_FLAG = '0'")
@Data
public class BpWorkSafetyIdentify  implements Serializable {

    //危害辨识id
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    private Long id;

    //作业证id
    @Column(name = "cert_id")
    private Long certId;

    //作业证类型
    @Column(name = "type")
    private String type;

    //危险辨识内容
    @Column(name = "content")
    private String content;

    //签名id
    @Column(name = "signer_id")
    private Long signerId;

    @org.springframework.data.annotation.CreatedBy
    @Column(name = "create_by")
    private Long createBy;

    @org.springframework.data.annotation.CreatedDate
    @Column(name = "create_time")
    private Date createTime;

    @org.springframework.data.annotation.LastModifiedBy
    @Column(name = "update_by")
    private Long updateBy;

    @org.springframework.data.annotation.LastModifiedDate
    @Column(name = "update_time")
    private Date updateTime;

    @Column(name = "delete_flag")
    private String deleteFlag;

    @Column(name = "org_code")
    private String orgCode;

    @Column(name = "tenent_id")
    private Long tenentId;

    public int hashCode() {
        return new HashCodeBuilder().append(getId()).toHashCode();
    }

    public boolean equals(Object obj) {
        if (obj instanceof BpWorkSafetyIdentify == false)
            return false;
        if (this == obj)
            return true;
        BpWorkSafetyIdentify other = (BpWorkSafetyIdentify) obj;
        return new EqualsBuilder().append(getId(), other.getId()).isEquals();
    }
}
